package com.akjava.lib.android.game;

import android.content.Context;
import android.content.SharedPreferences;

import com.akjava.lib.android.opengl.AbstractRenderer;




public abstract class AbstractGLGameRender extends AbstractRenderer  implements GameRender{

	
	protected int controlerFlags=CONTROL_DPAD | CONTROL_TOUCH_SCREEN;
	
	
	protected int stage;
	
	protected long lastTouch;
	protected long doubleTouchTime=500;

	private long on_touch_current;

	private boolean on_touch_result;
	public int getStage() {
		return stage;
	}






	public int getControlerFlags() {
		return controlerFlags;
	}



	public void setControlerFlags(int controlerFlags) {
		this.controlerFlags = controlerFlags;
	}




	
	public boolean isControlerMotionSensor(){
		return (controlerFlags & CONTROL_MOTION_SENSOR)==CONTROL_MOTION_SENSOR;
	}
	
	public boolean isControlerDPad(){
		return (controlerFlags & CONTROL_DPAD)==CONTROL_DPAD;
	}
	
	public boolean isControlerTouchScreen(){
		return (controlerFlags & CONTROL_TOUCH_SCREEN)==CONTROL_TOUCH_SCREEN;
	}
	
	
	public AbstractGLGameRender(Context context) {
		super(context);
	}
	
	
    public boolean onTouchDown(final float x,final float y){
    	on_touch_current = System.currentTimeMillis();
    	if(on_touch_current<lastTouch+doubleTouchTime){
    		on_touch_result = onDoubleTouch(x,y);
    		if(on_touch_result==true){
    			return true;
    		}
    	}
    	lastTouch=on_touch_current;
    	return onSingleTouch(x,y);
    }

    public abstract boolean onSingleTouch(float x,float y);
    
    public abstract boolean onDoubleTouch(float x,float y);
    
    public abstract void loadSharedPreference(SharedPreferences settings);
}
